package com.example.weight.navigation;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
import com.example.weight.R;
import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;

public class YoujiziyuanzaishengCenterNavigationActivity extends AppCompatActivity {

    private Button gongyixianchangNav, shengchanxianchangNav;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_youjiziyuanzaisheng_center_nav);

        Intent previousIntent = getIntent();
        final String name = previousIntent.getStringExtra("name");
        final String factory = previousIntent.getStringExtra("factory");
        String permissionLevel = previousIntent.getStringExtra("permissionLevel");

        TitleBar titleBar = findViewById(R.id.main_navigation_titleBar);
        titleBar.setOnTitleBarListener(new OnTitleBarListener() {
            @Override
            public void onLeftClick(View v) {
                finish();
            }

            @Override
            public void onTitleClick(View v) {}

            @Override
            public void onRightClick(View v) {}
        });

        gongyixianchangNav = findViewById(R.id.gongyixianchang_nav);
        shengchanxianchangNav = findViewById(R.id.shengchanxianchang_nav);


        gongyixianchangNav.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(YoujiziyuanzaishengCenterNavigationActivity.this, GongyixianchangNavigationActivity.class);
                intent.putExtra("name", name);
                intent.putExtra("factory", factory);
                if (permissionLevel.equals("0"))
                    intent.putExtra("permissionLevel", "0");
                else
                    intent.putExtra("permissionLevel", permissionLevel);
                startActivity(intent);
            }
        });

        shengchanxianchangNav.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(YoujiziyuanzaishengCenterNavigationActivity.this, ShengchanxianchangNavigationActivity.class);
                intent.putExtra("name", name);
                intent.putExtra("factory", factory);
                if (permissionLevel.equals("0"))
                    intent.putExtra("permissionLevel", "0");
                else
                    intent.putExtra("permissionLevel", permissionLevel);
                startActivity(intent);
            }
        });
        initNavEnable(permissionLevel);
    }
    private void initNavEnable(String permissionLevel) {
        if (permissionLevel.startsWith("0"))
            return;
        gongyixianchangNav.setEnabled(false);
        shengchanxianchangNav.setEnabled(false);
        if (permissionLevel.contains("工艺现场")) {
            // 四季青相关人员
            gongyixianchangNav.setEnabled(true);
        }
        if (permissionLevel.contains("生产现场")) {
            shengchanxianchangNav.setEnabled(true);
        }
    }
}
